<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <link href="__LAYUIADMIN__/res/layui/css/layui.css" rel="stylesheet">
</head>

<body>
    <div class="layui-container" style="padding: 20px;">
        <form class="layui-form" lay-filter="cardForm">
            <!-- 会员等级类型 -->
            <div class="layui-form-item">
                <label class="layui-form-label">会员等级</label>
                <div class="layui-input-block">
                    <select name="membership_type_id" lay-verify="required">
                        <option value="">请选择</option>
                        {foreach $membershipList as $k => $v}
                        <option value="{$v.id}">{$v.cname}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

            <!-- 时间单位 -->
            <div class="layui-form-item">
                <label class="layui-form-label">时间单位</label>
                <div class="layui-input-block">
                    <select name="unit" lay-verify="required">
                        <option value="0">小时</option>
                        <option value="1">天</option>
                        <option value="2">月</option>
                    </select>
                </div>
            </div>
            <!-- 数量 -->
            <div class="layui-form-item">
                <label class="layui-form-label">时间数量</label>
                <div class="layui-input-block">
                    <input type="number" name="quantity" lay-verify="required|number" placeholder="请输入时间数量"
                        class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">生成数量</label>
                <div class="layui-input-block">
                    <input type="number" name="num" lay-verify="required|number" placeholder="请输入生成数量"
                        class="layui-input">
                </div>
            </div>
            <!-- 提交按钮 -->
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="submitBtn">立即生成</button>
                </div>
            </div>
        </form>
    </div>
    <script src="__LAYUIADMIN__/res/layui/layui.js"></script>

    <script>
        layui.use(['form', 'layer'], function () {
            var form = layui.form,
                layer = layui.layer;
            $ = layui.$;

            // 表单验证规则（可选扩展）
            form.verify({
                number: function (value) {
                    if (value <= 0) return "数量必须大于0";
                }
            });

            // 监听表单提交
            form.on('submit(submitBtn)', function (data) {
                // 显示加载动画
                $.ajax({
                    url: '/admin/fake/doAdd',
                    type: 'POST',
                    data: data.field,
                    success: function (res) {
                        layer.closeAll('loading');
                        if (res.code === 200) {
                            layer.msg('生成成功', { icon: 1 });
                        } else {
                            layer.msg(res.msg || '生成失败', { icon: 2 });
                        }
                    },
                    error: function () {
                        layer.closeAll('loading');
                        layer.msg('请求异常', { icon: 2 });
                    }
                });
                return false;
            });
        });
    </script>
</body>

</html>